package org.wangle.order.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;
import org.wangle.api.goods.pojo.Goods;
import org.wangle.api.order.pojo.Orders;
import org.wangle.api.order.provider.OrdersProvider;
import org.wangle.api.user.pojo.User;
import org.wangle.order.mapper.OrdersMapper;
import org.wangle.order.publisher.SecKillPublisher;

import javax.annotation.Resource;


@Service(protocol = "dubbo")
@Component
public class OrdersProviderImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersProvider {

    @Resource
    private SecKillPublisher secKillPublisher;


    @Resource
    private OrdersMapper ordersMapper;
    @Override
    public Object creatOrder(User user, Goods goods) {
        Orders order = new Orders();
        order.setGoodsId(goods.getId());
        order.setUserId(user.getId());
        order.setState(1);
        secKillPublisher.sendMsg(order);
        return order;
    }

    @Override
    public void deleteAll() {
        ordersMapper.deleteAll();
    }



}
